/*****************************************************************************
 *   Copyright (C) 2008 John Schember <john@nachtimwald.com>                 *
 *                                                                           *
 *   This file is part of niwwidgets.                                    *
 *                                                                           *
 *   niwwidgets is free software: you can redistribute it and/or         *
 *   modify it under the terms of the GNU General Public License as          *
 *   published by the Free Software Foundation, either version 3 of the      *
 *   License, or (at your option) any later version.                         *
 *                                                                           *
 *   niwwidgets is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            *
 *   GNU General Public License for more details.                            *
 *                                                                           *
 *   You should have received a copy of the GNU General Public License       *
 *   along with niwwidgets. If not, see                                  *
 *   <http://www.gnu.org/licenses/>.                                         *
 *****************************************************************************/

#include "niwfindwidget.h"

NiwFindWidget::NiwFindWidget(QWidget *parent) : QWidget(parent)
{
    setupUi(this);
}

void NiwFindWidget::setCloseIcon(const QIcon &icon)
{
    closeButton->setIcon(icon);
}

void NiwFindWidget::setPreviousIcon(const QIcon &icon)
{
    previousButton->setIcon(icon);
}

void NiwFindWidget::setNextIcon(const QIcon &icon)
{
    nextButton->setIcon(icon);
}

void NiwFindWidget::setFocus()
{
    findEdit->setFocus();
    findEdit->selectAll();
}

void NiwFindWidget::on_closeButton_clicked()
{
    emit wantsToClose();
}

void NiwFindWidget::on_findEdit_returnPressed()
{
    on_nextButton_clicked();
}

void NiwFindWidget::on_previousButton_clicked()
{
    NiwFindWidget::NiwFindFlags flags = NiwFindWidget::BACKWARD;

    if (caseCheck->isChecked()) {
        flags |= NiwFindWidget::CASESENSITIVE;
    }

    emit findText(findEdit->text(), flags);
}

void NiwFindWidget::on_nextButton_clicked()
{
    NiwFindWidget::NiwFindFlags flags = NiwFindWidget::FORWARD;

    if (caseCheck->isChecked()) {
        flags |= NiwFindWidget::CASESENSITIVE;
    }

    emit findText(findEdit->text(), flags);
}
